package org.jeecg.modules.paycenter.enums;

import org.apache.commons.lang.StringUtils;
import org.jeecg.common.exception.JeecgBootException;

import java.util.HashMap;
import java.util.Map;

public enum PayChannelEnum {
    NH("1"), //农行
    ZX("2"), //中信
    PF("6"), //浦发
    OFFLINE("5"),//线下
    TONGLIAN("7"),//通联
    PINGAN("8"),//平安
    HUNDSUN("9"),//徽商
    ZHENGZHOU("10"), //郑州银行
    ;
    public final String channelType;
    private static Map<String, PayChannelEnum> _channelsMap = new HashMap<>();

    PayChannelEnum(String channelType) {
        this.channelType = channelType;
    }

    static {
        for (PayChannelEnum item : PayChannelEnum.values()) {
            _channelsMap.put(item.channelType, item);
        }
    }

    public static PayChannelEnum getChannel(String channelType) {
        if (StringUtils.isEmpty(channelType)) {
            throw new JeecgBootException("支付渠道错误");
        }
        // 优化查找，改为map
        PayChannelEnum channelEnum = _channelsMap.get(channelType);
        if (channelEnum == null) {
            throw new JeecgBootException("支付渠道错误");
        }
        return channelEnum;
    }
}
